<?php

class userlog {
	public function __construct($user) {
		$this->user = $user;
	}

	public function get_last_logins() {
		echo '<div class="log_table_h1">10 last logins</div>';
		echo '<table><tr>';
		echo '<td class="header" width="130">from</td><td class="header" width="350">Browser / Agent</td><td class="header" width="150">login</td><td class="header" width="100">logout</td>';
		echo '</tr>';

		$sql = "SELECT ip, user, agent, login, logout FROM logins WHERE user='".$this->user."' ORDER BY id DESC LIMIT 10";
		$result = mysql_query($sql);
		while($row = mysql_fetch_assoc($result)) {
			if($row['logout'] == NULL) { $row['logout'] = 'Active'; }
			echo '<tr>';
			echo '<td class="log">' . $row['ip'] . '</td>';
			echo '<td class="log">' . substr($row['agent'], 0, -20) . '.. </td>';
			echo '<td class="log">' . $row['login'] . '</td>';
			echo '<td class="log">' . $row['logout'] . '</td>';
			echo '</tr>';
		}
		echo "</table>";
	}
}

?>
